package com.xianrenit.xianrenpuzi.manager.controller;

import com.xianrenit.xianrenpuzi.manager.service.SysUserService;
import com.xianrenit.xianrenpuzi.model.dto.sys.SysUserSearchDto;
import com.xianrenit.xianrenpuzi.model.entity.sys.SysUser;
import com.xianrenit.xianrenpuzi.model.result.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/admin/system/user")
public class SysUserController {
    @Resource
    SysUserService sysUserService;
    @Operation(summary = "根据id查询用户")
    @GetMapping("getById/{id}")
    public Result getById(@PathVariable("id")Long id){
        //删除时也可能前端需要得到删除的行数据
        SysUser sysUser = sysUserService.getById(id);
        return Result.ok(sysUser);
    }
    @Operation(summary = "更新用户")
    @PutMapping("update")
    public Result update(@RequestBody SysUser sysUser){
        sysUserService.update(sysUser);
        return Result.ok();
    }
    @Operation(summary = "新增用户")
    @PostMapping("save")
    public Result save(@RequestBody SysUser sysUser){
        sysUserService.save(sysUser);
        return Result.ok();
    }

    @Operation(summary = "删除指定用户")
    @DeleteMapping("deleteById/{id}")
    public Result deleteById(@PathVariable("id")Long id){
        //删除时也可能前端需要得到删除的行数据
        sysUserService.deleteById(id);
        return Result.ok();
    }
    @Operation(summary = "条件查询用户分页数据")
    @GetMapping("list/{pageNum}/{pageSize}")// url?start=xxx&end=xxx
    public Result listUsers(SysUserSearchDto sysUserSearchDto, //接收请求参数
                            @PathVariable("pageNum") Integer pageNum ,
                            @PathVariable("pageSize")  Integer pageSize){
        PageInfo<SysUser> page = sysUserService.listUsers(sysUserSearchDto,pageNum,pageSize);
        return Result.ok(page);
    }
}
